﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace Medianamik.UI.Controls
{
    public class IsHttpsSelector : BaseMedianamikControl 
    {
        RadioButton _rbHttp = new RadioButton()
        {
            Text = "http://",
            Checked = true,
            GroupName = "IsHttpsSelector",
            CssClass = "RadioButton"
        };

        RadioButton _rbHttps = new RadioButton()
        {
            Text = "https://",
            Checked = false,
            GroupName = "IsHttpsSelector",
            CssClass = "RadioButton"
        };


        public override object GetValue()
        {
            EnsureChildControls();
            return _rbHttps.Checked;
        }

        public override void SetValue(object value)
        {
            EnsureChildControls();
            _rbHttps.Checked = (bool)value;
        }

        public override Type TypeOfValue
        {
            get { return typeof(bool); }
        }

        protected override void CreateControlHierarchy(bool pUseDataSource)
        {
            Controls.Add(_rbHttp);
            Controls.Add(new LiteralControl("<br />")); 
            Controls.Add(_rbHttps);

            if (pUseDataSource)
            {
                bool isHttps = (bool?)DataSource ?? false;
                _rbHttp.Checked = !isHttps;
                _rbHttps.Checked = isHttps;
            }
        }
    }
}
